package abstractclass;

public class TestGeometricObject {
  /** Main method */
  public static void main(String[] args) {
    // Declare and initialize two geometric objects
    GeometricObject geoObject1 = new Circle(5);
    GeometricObject geoObject2 = new Rectangle(5, 3);
    GeometricObject geoObject3 = new Square(5);

    System.out.println("The two objects have the same area? " +
      equalArea(geoObject1, geoObject2));

    // Display circle
    displayGeometricObject(geoObject1);

    // Display rectangle
    displayGeometricObject(geoObject2);

    displayGeometricObject(geoObject3);

    System.out.println();
    System.out.println("最大的面积为："+maxArea(geoObject1,geoObject2,geoObject3));
    System.out.println("最短的周长为："+minPerimeter(geoObject1,geoObject2,geoObject3));
  }

  /** A method for comparing the areas of two geometric objects */
  public static boolean equalArea(GeometricObject object1, GeometricObject object2) {
    return object1.getArea() == object2.getArea();
  }

  /** A method for displaying a geometric object */
  public static void displayGeometricObject(GeometricObject object) {
    System.out.println();
    System.out.println("The area is " + object.getArea());
    System.out.println("The perimeter is " + object.getPerimeter());
  }

  public static double minPerimeter(GeometricObject object1,GeometricObject object2,GeometricObject object3){
    double min = 0;
    if(object1.getPerimeter()<object2.getPerimeter()){
      if (object1.getPerimeter()<object3.getPerimeter()){
        min = object1.getPerimeter();
      }else {
        min = object3.getPerimeter();
      }
    }else {
      if (object2.getPerimeter()<object3.getPerimeter()){
        min = object2.getPerimeter();
      }else {
        min = object3.getPerimeter();
      }
    }
    return min;
  }

  public static double maxArea(GeometricObject object1,GeometricObject object2,GeometricObject object3){
    double max = 0;
    if(object1.getArea()>object2.getArea()){
      if (object1.getArea()>object2.getArea()){
        max = object1.getArea();
      }else {
        max = object2.getArea();
      }
      if (object3.getArea()>max){
        max = object3.getArea();
      }
    }
    return max;
  }

}
